package com.example.searchservice.service.impl;

import org.springframework.stereotype.Service;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

@Service
public class WordSegmentationServiceImpl {

    public List<String> segment(String text) throws IOException {
        List<String> result = new ArrayList<>();
        StringReader reader = new StringReader(text);
        IKSegmenter ikSegmenter = new IKSegmenter(reader, true);
        Lexeme lexeme;
        while ((lexeme = ikSegmenter.next()) != null) {
            result.add(lexeme.getLexemeText());
        }
        return result;
    }

}